home *** CD-ROM | disk | FTP | other *** search
/ ftp.hitl.washington.edu / ftp.hitl.washington.edu.tar / ftp.hitl.washington.edu / pub / people / tsoper / CT Explorer / 3DElementIndexer.cs next >
Text File  |  2005-06-07  |  4KB  |  206 lines

  1. //3DElementIndexer.cs
  2. //This class was written to ease conversion between scan coordinates
  3. //in row-column-plane (RCP) to right-handed cartesian coordinates
  4. //in x-y-z (XYZ). With this class, respective correspondence between 
  5. //matrix dimensions, and 3D axes is set up once precluding a lot of 
  6. //confusing code. The indexer only stores the RCP index subscripts in 
  7. //the 3 element vector rcpIndex. The xyzCorr vector containes possible 
  8. //values of 0,1, or 2. The ith element of xyzCorr correlates with the 
  9. //ith axis in XYZ where X=0, Y=1, Z=2. The value stored there 
  10. //corresponds to the dimension of the matrix in RCP where row = 0, 
  11. //column = 1, plane = 2. The isNegative vector specifices if any 
  12. //indexes need to be negated before converting RCP to XYZ. No XYZ data 
  13. //is stored; all accessors convert from RCP when the data is retrieved.
  14. //THIS CLASS IS NOT LINKED TO DATA, IT IS JUST AN INDEX.
  15.  
  16. //THINGS TO DO: 1) switch out vectors for class with xyz or rcp properties
  17. //                2) change method inputs to (AXIS) enumeration rather than int
  18.  
  19. using System;
  20.  
  21. public enum AXIS_ALIGN
  22. {
  23.     POSITIVE_X,
  24.     POSITIVE_Y,
  25.     POSITIVE_Z,
  26.     NEGATIVE_X,
  27.     NEGATIVE_Y,
  28.     NEGATIVE_Z,
  29. }
  30.     
  31. public class ElementIndexer3D
  32. {
  33.     
  34.  
  35.     //Attributes
  36.     private int[] rcpIndex = new int[3];    //actual index is stored in 
  37.                                             //RCP format
  38.  
  39.     private int[] xyzCorr = new int[3];        //correspondence of 
  40.                                             //xyz to rcp
  41.     
  42.     private bool[] isNegative = new bool[3];  //negative axis corresp.
  43.     
  44.     float[] scaleFactor = new float[3];        //scaling of rcp to xyz
  45.  
  46.     //Properties
  47.     public int X        //get/set the X element
  48.     {
  49.         get
  50.         {
  51.             return GetXYZElement(0);
  52.         }
  53.         set
  54.         {
  55.             SetXYZElement(0,value);
  56.         }
  57.     }
  58.       
  59.     public int Y        //get/set the Y element
  60.     {
  61.         get
  62.         {
  63.             return GetXYZElement(1);
  64.         }
  65.         set
  66.         {
  67.             SetXYZElement(1,value);
  68.         }
  69.     }
  70.     
  71.     public int Z        //get/set the Z element
  72.     {
  73.         get
  74.         {
  75.             return GetXYZElement(2);
  76.         }
  77.         set
  78.         {
  79.             SetXYZElement(2,value);
  80.         }
  81.     }
  82.             
  83.  
  84.     public int Row        //get/set the Row element
  85.     {
  86.         get
  87.         {
  88.             return rcpIndex[0];
  89.         }
  90.         set
  91.         {
  92.             rcpIndex[0] = value;
  93.         }
  94.     }
  95.     
  96.     public int Column    //get/set the Column element
  97.     {
  98.         get
  99.         {
  100.             return rcpIndex[1];
  101.         }
  102.         set
  103.         {
  104.             rcpIndex[1] = value;
  105.         }
  106.     }
  107.             
  108.     public int Plane    //get/set the Plane element
  109.     {
  110.         get
  111.         {
  112.             return rcpIndex[2];
  113.         }
  114.         set
  115.         {
  116.             rcpIndex[2] = value;
  117.         }
  118.     }
  119.         
  120.  
  121.     public int[] RCPIndex    //get/set the full RCP index vector
  122.     {
  123.         get
  124.         {
  125.             return (int[])rcpIndex.Clone();
  126.         }
  127.         set
  128.         {
  129.             rcpIndex[0] = value[0];
  130.             rcpIndex[1] = value[1];
  131.             rcpIndex[2] = value[2];
  132.         }
  133.     }
  134.  
  135.     public int[] XYZIndex    //get/set the full XYZ index vector
  136.     {
  137.         get
  138.         {
  139.             int[] xyzIndex = {X,Y,Z};
  140.             return xyzIndex;
  141.         }
  142.         set
  143.         {
  144.             X = value[0];
  145.             Y = value[1];
  146.             Z = value[2];
  147.         }
  148.     }
  149.  
  150.  
  151.     //overloaded constructors:
  152.     public ElementIndexer3D(AXIS_ALIGN xCorr,AXIS_ALIGN yCorr, 
  153.                             AXIS_ALIGN zCorr)
  154.     {
  155.         AXIS_ALIGN[] corr = {xCorr,yCorr,zCorr};
  156.         MakeAssignments(corr);
  157.     }
  158.  
  159.     public ElementIndexer3D(AXIS_ALIGN[] corr)
  160.     {
  161.         MakeAssignments(corr);
  162.     }
  163.  
  164.     //Assign correspondences in the xyzCorr variable
  165.     private void MakeAssignments(AXIS_ALIGN[] corr)
  166.     {
  167.         for(int i =0; i < 3; i++)
  168.         {
  169.             int axisCorr = (int)corr[i]; //convert enum to int
  170.  
  171.             //adjust if it is negative
  172.             if (axisCorr >= 3)
  173.             {
  174.                 isNegative[i] = true;
  175.                 axisCorr -= 3;
  176.             }
  177.             else 
  178.                 isNegative[i] = false;
  179.  
  180.             xyzCorr[i] = axisCorr; //set the correspndence
  181.         }
  182.     }
  183.  
  184.     //set
  185.     public int GetXYZElement(int axis)
  186.     {
  187.         if(isNegative[axis])
  188.             return -rcpIndex[xyzCorr[axis]];
  189.         else
  190.             return rcpIndex[xyzCorr[axis]];
  191.     }
  192.  
  193.     public void SetXYZElement(int axis, int index)
  194.     {
  195.             rcpIndex[xyzCorr[axis]] = Math.Abs(index); 
  196.                                     //force subscripts to be +
  197.     }
  198.  
  199.     private void SetRCPElement(int dimension, int index)
  200.     {
  201.         rcpIndex[dimension] = index;
  202.     }
  203.  
  204.     
  205. }
  206.